﻿<!doctype html>
 <html lang="zh-CN">
 <head>
   <meta charset="UTF-8">
   <link rel="stylesheet" href="${req.contextPath}/css/common.css">
   <link rel="stylesheet" href="${req.contextPath}/css/main.css">
   <script type="text/javascript" src="${req.contextPath}/js/jquery.min.js"></script>
   <script type="text/javascript" src="${req.contextPath}/js/colResizable-1.3.min.js"></script>
   <script type="text/javascript" src="${req.contextPath}/js/common.js"></script>

</head>
<body>
<form id="formData">
     <div id="search_bar" class="mt10">

       <div class="box">
          <div class="box_border">
            <div class="box_top"><b class="pl15">会议室预定</b></div>
            <div class="box_center pt10 pb10">
              <table class="form_table" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td>预定时间段</td>
                    <input type="hidden" id="newDate">
                  <td>
                      <#if endTime! == "">
                        <input type="datetime-local" id="startTime" name="startTime" min  max class="input-text lh25" size="10">to
				        <input type="datetime-local" id="endTime" name="endTime" min  max class="input-text lh25" size="10">(预定时间段必须为同一天)
                      <#else >
                        <input type="datetime-local" id="startTime" name="startTime" min  max value="${startTime}" class="input-text lh25" size="10">to
                        <input type="datetime-local" id="endTime" name="endTime" min  max value="${endTime}" class="input-text lh25" size="10">(预定时间段必须为同一天)
                      </#if>
                  </td>
                </tr>
              </table>
            </div>
          </div>
          </div>
       </div>
     </div>

    <div id="table" class="mt10">
        <div class="box span10 oh">
              <table width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table">

                  <tr>
                      <th >选择 </th>
                      <th >会议室名称</th>
                      <th >会议室描述</th>
                  </tr>
                  <#list pageInfo.list as list>
                      <tr class="tr" align="center">
                          <td class="td_center" ><input type="radio" id="meetId" name="meetId" value="${list.meetId}" /></td>
                          <td>${list.meetName}</td>
                          <td>${list.meetDesc}</td>
                      </tr>
                  </#list>

                  <tr>
			   <td colspan="2">会议室预定人:<input type="text" id="realName" name="realName" readonly value="${user.realName}">
			    会议类型:
                   &nbsp;<select class="input-text lh25" id="meetTypeId" name="meetTypeId">
                            <option value="">-请选择-</option>
                       <#list typeList as type>
				            <option value="${type.typeId}">${type.typeName}</option>
                       </#list>
				  </select>
                 下一步审批人:&nbsp;
                   <select class="input-text lh25" id="userId" name="userId">
                       <option value="">-请选择-</option>
				        <option value="2">行政主管</option>
				  </select>
				  <input type="button" onclick="reserve()" class="input-text lh25"  value="预定">
				  <input type="button"  class="input-text lh25"  value="返回" onclick="location.href='javascript:history.go(-1)'">
				</td>
                      <td colspan="5" align="right">
                          <div class="page mt10">
                              <div class="pagination">
                                  <ul >
                                      <#if ids??   >

                                          <input type="hidden" id="ids" value="${ids}" >

                                          <li class="first-child"><a href="javascript:;" onclick="page(1)">首页</a></li>
                                          <#if pageInfo.getPrePage() lt 1>
                                              <li>
                                                  <a href="javascript:;" onclick="page(1)">上一页</a>
                                              </li>
                                          <#else >
                                              <li>
                                                  <a href="javascript:;" onclick="page(${pageInfo.getPrePage()})">上一页</a>
                                              </li>
                                          </#if>

                                          <#if pageInfo.getNextPage() == 0>
                                              <li>
                                                  <a href="javascript:;" onclick="page(${pageInfo.getPages()})">下一页</a>
                                              </li>
                                          <#else >
                                              <li>
                                                  <a href="javascript:;" onclick="page(${pageInfo.getNextPage()})">下一页</a>
                                              </li>
                                          </#if>
                                          <li > <a href="javascript:;" onclick="page(${pageInfo.getPages()})">末页</a></li>
                                          <li ><span>共${pageInfo.total}条数据</span></li>
                                          <li ><span>共${pageInfo.getPages()}页</span></li>

                                      <#else >

                                          <li class="first-child"><a href="${req.contextPath}/administrative/ReserveMeet-ui">首页</a></li>
                                          <#if pageInfo.getPrePage() lt 1>
                                              <li>
                                                  <a href="${req.contextPath}/administrative/ReserveMeet-ui?page=1">上一页</a>
                                              </li>
                                          <#else >
                                              <li>
                                                  <a href="${req.contextPath}/administrative/ReserveMeet-ui?page=${pageInfo.getPrePage()}">上一页</a>
                                              </li>
                                          </#if>

                                          <#if pageInfo.getNextPage() == 0>
                                              <li>
                                                  <a href="${req.contextPath}/administrative/ReserveMeet-ui?page=${pageInfo.getPages()}">下一页</a>
                                              </li>
                                          <#else >
                                              <li>
                                                  <a href="${req.contextPath}/administrative/ReserveMeet-ui?page=${pageInfo.getNextPage()}">下一页</a>
                                              </li>
                                          </#if>
                                          <li ><a href="${req.contextPath}/administrative/ReserveMeet-ui?page=${pageInfo.getPages()}">末页</a></li>
                                          <li ><span>共${pageInfo.total}条数据</span></li>
                                          <li ><span>共${pageInfo.getPages()}页</span></li>

                                      </#if>
                                  </ul>
                              </div>
                          </div>
                      </td>
			   </tr>

              </table>
        </div>
    </div>
</form>
    <script type="text/javascript" src="${req.contextPath}/js/jquery.min.js"></script>
        <script>

             //设定最小预订时间
             $(function() {
                 //得到当前时间
                 var date_now = new Date();
                 //得到当前年份
                 var year = date_now.getFullYear();
                 //得到当前月份
                 //注：
                 //  1：js中获取Date中的month时，会比当前月份少一个月，所以这里需要先加一
                 //  2: 判断当前月份是否小于10，如果小于，那么就在月份的前面加一个 '0' ， 如果大于，就显示当前月份
                 var month = date_now.getMonth() + 1 < 10 ? "0" + (date_now.getMonth() + 1) : (date_now.getMonth() + 1);
                 //得到当前日子（多少号）
                 var date = date_now.getDate() < 10 ? "0" + date_now.getDate() : date_now.getDate();
                 //得到当前小时
                 var hour = date_now.getHours() < 10 ? "0" + date_now.getHours() : date_now.getHours();
                 //得到当前分钟
                 var minute = date_now.getMinutes() < 10 ? "0" + date_now.getMinutes() : date_now.getMinutes();
                 //设置input标签的min属性
                 // $("#startTime").attr("min", year + "-" + month + "-" + date + " " + date_now.getHours() + ":" + date_now.getMinutes());
                 $("#startTime").attr("min", year + "-" + month + "-" + date + "T" + hour + ":" +minute );
                 // $("#newDate").val(year + "-" + month + "-" + date + "T" + hour + ":" +minute);
             })

             //设定会议结束时间
             $("#startTime").blur(function () {

                 var date_now=new Date();
                 //得到当前年份
                 var Syear = date_now.getFullYear();

                 var Smonth = date_now.getMonth() + 1 < 10 ? "0" + (date_now.getMonth() + 1) : (date_now.getMonth() + 1);
                 //得到当前日子（多少号）
                 var Sdate = date_now.getDate() < 10 ? "0" + date_now.getDate() : date_now.getDate();
                 //得到当前小时
                 var Shour = date_now.getHours() < 10 ? "0" + date_now.getHours() : date_now.getHours();
                 //得到当前分钟
                 var Sminute = date_now.getMinutes() < 10 ? "0" + date_now.getMinutes() : date_now.getMinutes();

                 $("#newDate").val(Syear + "-" + Smonth + "-" + Sdate + "T" + Shour + ":" +Sminute);
                 //得到id=newDate的值
                 var newDate = $("#newDate").val();

                 //获取开始时间的值
                 var start = $("#startTime").val();
                //预约时间不能小于当前时间
                 if (start<newDate){
                     alert("预约时间不能小于当前时间!")
                     $("#startTime").val(null);
                     return;
                 }

                 var startTime = new Date(start.replace(/T/, " "));

                 //得到当前年份
                 var year = startTime.getFullYear();
                 //得到当前月份
                 //注：
                 //  1：js中获取Date中的month时，会比当前月份少一个月，所以这里需要先加一
                 //  2: 判断当前月份是否小于10，如果小于，那么就在月份的前面加一个 '0' ， 如果大于，就显示当前月份
                 var month = startTime.getMonth() + 1 < 10 ? "0" + (startTime.getMonth() + 1) : (startTime.getMonth() + 1);
                 //得到当前日子（多少号）
                 var date = startTime.getDate() < 10 ? "0" + startTime.getDate() : startTime.getDate();
                 //得到当前小时
                 var hour = startTime.getHours() < 10 ? "0" + startTime.getHours() : startTime.getHours();
                 //设置晚上九点后会议室不能再被预约
                 if (hour>=21){
                     alert("晚上九点后会议室不能再被预约!")
                     $("#startTime").val(null);
                     return;
                 }

                 var minute = startTime.getMinutes() < 10 ? "0" +startTime.getMinutes() : startTime.getMinutes();
                 //设置input标签的min属性  每一次时间不低于1小时
                 $("#endTime").attr("min", year + "-" + month + "-" + date + "T" + hour + ":" +minute );
                 $("#endTime").attr("max", year + "-" + month + "-" + date + "T" + "23" + ":" +"59" );
             });

             //当选会议结束时间前,先把开始时间选了
             $("#endTime").blur(function () {
                 //判断开始时间是否已选择
                 //获取开始时间的值
                 var start = $("#startTime").val();
                 if (start==null || start==""){
                     alert("请先选择开始时间")
                     $("#endTime").val(null);
                     return;
                 }

                 //把预定时间传至后台,判断此时间段有哪些可选的办公室
                 var endTime = $("#endTime").val();
                 $.post(
                     "${req.contextPath}/administrative/leisureId",
                     {
                         start:start,
                         endTime:endTime
                     },
                     function (result) {
                         if (result.code==0){
                             // $("#ids").val(result.data);
                            location.href="${req.contextPath}/administrative/ReserveMeet-ui?ids="+result.data+"&startTime="+start+"&endTime="+endTime;
                         }else {
                             alert("无可用会议室")
                         }
                     },
                     "json"
                 );
             });

             //携带ids参数的分页
             function page(page) {
                    //得到参数的值
                 var arrayId =[];
                 arrayId = $("#ids").val();
                 // alert(arrayId)

                 var ids = arrayId.toString();
                 // alert(1)
                 // alert(ids)
                 var startTime = $("#startTime").val();
                 var endTime = $("#endTime").val();
                 location.href="${req.contextPath}/administrative/ReserveMeet-ui?page="+page+"&ids="+ids+"&startTime="+startTime+"&endTime="+endTime;

             }

             //预定会议室
             function reserve() {

                 var sTime = new Date($("#startTime").val()).getTime();
                 // var sTime = new Date($("#startTime").val());
                 // var years = sTime.getFullYear();
                 // var months = sTime.getMonth() + 1 < 10 ? "0" + (sTime.getMonth() + 1) : (sTime.getMonth() + 1);
                 // var dates = sTime.getDate() < 10 ? "0" + sTime.getDate() : sTime.getDate();
                 // var hours = sTime.getHours() < 10 ? "0" + sTime.getHours() : sTime.getHours();
                 // var minutes = sTime.getMinutes() < 10 ? "0" + sTime.getMinutes() : sTime.getMinutes();
                 // var startTime=years+"-"+months+"-"+dates+" "+hours+":"+minutes;

                 var eTime = new Date($("#endTime").val()).getTime();

                 // var eTime = new Date($("#endTime").val());
                 // var yeare = eTime.getFullYear();
                 // var monthe = eTime.getMonth() + 1 < 10 ? "0" + (eTime.getMonth() + 1) : (eTime.getMonth() + 1);
                 // var datee = eTime.getDate() < 10 ? "0" + eTime.getDate() : eTime.getDate();
                 // var houre = eTime.getHours() < 10 ? "0" + eTime.getHours() : eTime.getHours();
                 // var minutee = eTime.getMinutes() < 10 ? "0" + eTime.getMinutes() : eTime.getMinutes();
                 // var endTime=yeare+"-"+monthe+"-"+datee+" "+houre+":"+minutee;

                 // var formData = new FormData();


                 // formData.append("startTime",$("#startTime").val());
                 // formData.append("endTime",$("#endTime").val());
                 var realName=$("#realName").val();
                 var meetId=$("#meetId").val();
                 var meetTypeId=$("#meetTypeId").val();
                 var userId=$("#userId").val();

                 //  alert(formData.get("endTime"))
                var st1 =$("#startTime").serialize().replace("T"," ");

                 var st2 =st1.replace("T"," ")

                 var st3 =st2.replace(" ","T")

                 // formData.append("startTime",st3);

                 var et1 =$("#endTime").serialize().replace("T"," ");

                 var et2 =et1.replace("T"," ")

                 var et3 =et2.replace(" ","T")


        if (
            sTime == null || eTime == null || realName == null ||meetId == null || meetTypeId == null || userId ==null ||
            sTime == "" || eTime == "" || realName =="" ||meetId == "" || meetTypeId == "" || userId ==""
        ){
            alert("请选择所有条件选项");
            return;
        }

                 // formData.append("endTime",et3);
                //  var formData = $("#formData").serialize();
                 $.ajax({
                     data:{
                         startTime:sTime,
                         endTime:eTime,
                         realName:realName,
                         meetId:meetId,
                         meetTypeId:meetTypeId,
                         userId:userId
                     },
                     type:"post",
                     dataType:"json",
                    url:"${req.contextPath}/administrative/ReserveMeet",
                 success:function(result){
                     if (result.code==0){
                         alert("添加成功")
                         location.href="${req.contextPath}/resource/xingzheng/demo1/list";
                     }else {
                         alert(result.msg)
                     }
                 }
                 });
              /*   $.post(

                     formData,
                     function (result) {
                         if (result.code==0){
                             alert("添加成功")
                             location.href="${req.contextPath}/resource/xingzheng/demo1/list";
                         }else {
                             alert(result.msg)
                         }
                     },
                 "json"
                 );*/
             }
             
         </script>

</body>
</html>